/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nageoffer.shortlink.admin.common.convention.result;

import java.io.Serial;
import java.io.Serializable;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @program: shortlink
 * @description: Java Lotus
 * @author: spring
 * @create: 2024-10-28
 * 全局返回对象
 */
@Data
@Accessors(chain = true)
public class Result<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 5679018624309023727L;

    /**
     * 正确返回码
     */
    public static final String SUCCESS_CODE = "0";

    /**
     * 返回码
     */
    private String code;

    /**
     * 返回消息
     */
    private String message;

    /**
     * 响应数据
     */
    private T data;

    /**
     * 请求ID
     */
    private String requestId;

    /**
     * 返回true or false
     *
     * @return 判断
     */
    public boolean isSuccess() {
        return SUCCESS_CODE.equals(code);
    }


}

/*
注解的作用
@Accessors(chain = true) 是 Lombok 库中的一个注解，
用于简化 Java 类的属性访问器（getter 和 setter）方法的生成。
1.链式调用：当 chain 属性设置为 true 时，Lombok 会生成返回当前对象的 setter 方法。这允许您在设置多个属性时使用链式调用的方式
2.简化代码：通过使用 @Accessors(chain = true)，您可以减少手动编写 getter 和 setter 方法的工作量，从而使代码更加简洁和易读。
3.可选配置：除了 chain 属性外，@Accessors 注解还可以配置其他属性，例如 fluent，用于生成无参数的访问器方法。
 */